package com.docman.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.docman.dao.CommentDAO;
import com.docman.domainmodel.CommentBean;


@WebServlet("/CommentServlet")
public class CommentServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
    public CommentServlet() {
        super();
        
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("text/html;  charset=utf-8");
		request.setCharacterEncoding("UTF-8");
		
		CommentBean comment = new CommentBean();
		
		int docId = Integer.parseInt(request.getParameter("docId"));
		String commenter = request.getParameter("commenter");
		String userComment = request.getParameter("comment");
		
		java.util.Date myDate = new java.util.Date();
		java.sql.Date sqlDate = new java.sql.Date(myDate.getTime());
		
		comment.setDocId(docId);
		comment.setCommenter(commenter);
		comment.setComment(userComment);
		comment.setCommentDate(sqlDate);
		
		CommentDAO.setComment(comment);
		
		
		
		response.sendRedirect("/sys0.1/documentInfoServletpath?docId="+docId);
		
	}

}
